package com.fabriciojf.action;

import com.fabriciojf.controller.Action;
import com.fabriciojf.model.Category;
import com.fabriciojf.persistence.JpaPersistence;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Action
 *
 * @author Fabricio S Costa fabriciojf@gmail.com
 * @since 01/12/2009
 * @version 1.0
 */
public class SalvarCategoriaAction implements Action {

    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response) throws IOException {
        
        String nomeCategoria = request.getParameter("categoria");

        try {
            Category categoria = new Category(nomeCategoria);
            JpaPersistence.getInstance().save(categoria);

            response.sendRedirect("FrontController?action=ManutencaoCategoria");
        } catch (Exception ex) {
            response.sendRedirect("./erro.jsp");
            ex.printStackTrace();
        }
    }
}